import { _decorator, Component, Node } from 'cc';
import Config from '../util/Config';
import { WECHAT } from 'cc/env';
const { ccclass, property } = _decorator;

@ccclass('SDKManager')
export default class SDKManager {
    private static appId: string = "wx21fb5759ac3f5264"
    private static videoAd: string = "adunit-c3740b19943ee2e6"

    // 初始化
    public static initSDK() {
        let params = {
            "appId": SDKManager.appId,
            "version": Config.versionCode,
            "gameName": Config.gameName,
            "videoAdUnitID": SDKManager.videoAd,
            "isOpenLog": true
        };

        window.gameSdk.sdk.init({...params,callback(err,res){
            if(!err){
                console.log(err,res);
                // ab测标签
                const testTags = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'];
                const abTestTag = testTags[res.sdkConfig.abTest] || 'Z';
                console.log(`后台配置判断，是${abTestTag}测试用户`);

                // 获取后台配置
                window.gameSdk.sdk.getBackStageConfig({callback(err,res){
                    console.log("获取配置====",res);
                }})
            }
        }});
    }

    // 播放激励视频
    public static showRewardVideoAd(positionTag, callback) {
        if (WECHAT) {
            window.gameSdk.sdk.showRewardVideoAd({
                positionTag: positionTag,
                callback: (err, res) => {
                    callback(err, res)
                }
            })
        }
    }

    // 激活上报
    public static activeReport() {
        window.gameSdk.sdk.activeReport()
    }
}

